package designPattern.adaptor适配器模式.demo03;

public class MotorAdapterTest {

    public static void main(String[] args) {
        Motor electricAdaptor = new ElectricAdaptor(new ElectricMotor());
        electricAdaptor.drive();

        System.out.println();

        Motor opticalAdaptor = new OpticalAdaptor(new OpticalMotor());
        opticalAdaptor.drive();
    }
}

// 电能发动机
class ElectricMotor {
    public void electricMotorDrive() {
        System.out.println("electric motor drive");
    }
}

// 光能发动机
class OpticalMotor {
    public void opticalMotorDrive() {
        System.out.println("optical motor drive");
    }
}



// 发动机适配器接口
interface Motor {
    void drive();
}

// 电能发动机适配器
class ElectricAdaptor implements Motor {
    private ElectricMotor electricMotor;

    public ElectricAdaptor(ElectricMotor electricMotor) {
        this.electricMotor = electricMotor;
    }

    @Override
    public void drive() {
        this.electricMotor.electricMotorDrive();
    }
}

// 光能发动机适配器
class OpticalAdaptor implements Motor {
    private OpticalMotor opticalMotor;

    public OpticalAdaptor(OpticalMotor opticalMotor) {
        this.opticalMotor = opticalMotor;
    }

    @Override
    public void drive() {
        this.opticalMotor.opticalMotorDrive();
    }
}
